var t = require("../../../@babel/runtime/helpers/createForOfIteratorHelper"), a = require("../../../mybehaviors/location/location"), e = getApp();

Page({
    behaviors: [ a ],
    data: {
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        page: 1,
        ads: [],
        total_page: 0,
        category: [],
        loading: !1,
        isLoadMore: !0,
        stores: [],
        carousels: [],
        bannerData: [],
        shop: "",
        is_open: 0,
        Height: 0,
        LastHeight: 0,
        hot_arrondi: {},
        plugin_name: "拓客卡",
        openTemplate: 0
    },
    gettitle: function() {
        var t = wx.getStorageSync("yz_basic_info"), a = "";
        t && t.home && t.home.mailInfo && (a = t.home.mailInfo.name || ""), console.log(t.home.mailInfo.name, "basic_info.home.mailInfo.name"), 
        wx.setNavigationBarTitle({
            title: a
        });
    },
    onLoad: function(t) {
        var a = this;
        if (t.mid && e._setMid(t.mid), t.addressData) {
            var o = JSON.parse(t.addressData);
            this.setData({
                "point.lat": o.latitude,
                "point.lng": o.longitude,
                address: o.title,
                title: o.title,
                city: o.city
            }), this.getStorePage();
        } else this._getLocation(function(t) {
            var e = wx.getStorageSync("address-point");
            a.setData({
                address: e.city
            }), a.getStorePage();
        }, function(t) {
            a.getStorePage();
        });
    },
    imgHeight: function(t) {
        var a = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        parseInt(a) > this.data.LastHeight && (this.setData({
            Height: a
        }), this.data.LastHeight = parseInt(a));
    },
    onReady: function() {
        this.storeList = this.selectComponent("#storeList"), this.business = this.selectComponent("#business");
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.stores.length > 0 && !this.data.is_open && this.storeList.getMoreStores(), 
        this.data.shop && this.data.is_open && this.business.getMoreList();
    },
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: "",
            path: "packageC/o2o/o2oHome/o2oHome?mid=" + a
        };
    },
    onShareAppMessage: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            path: "/packageC/o2o/o2oHome/o2oHome?mid=" + a
        };
    },
    getStores: function(t) {
        this.setData({
            total_page: t.last_page
        }), this.data.total_page || this.setData({
            total_page: 0
        }), (t.total <= 0 || t.current_page == t.last_page) && this.setData({
            isLoadMore: !1
        }), this.setData({
            stores: t.data
        });
    },
    getStoresCategory: function() {
        var t = this, a = e.getNetAddresss("plugin.store-cashier.frontend.store.store-category.get-list");
        e._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    t.setData({
                        category: e.data ? e.data : []
                    });
                    var o = t.chunk(t.data.category, 10);
                    t.setData({
                        category_10: o
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _indexData: function(t) {
        this.setData({
            bannerData: t.banner,
            carousels: t.carousels ? t.carousels : [],
            ads: t.advs
        });
    },
    chunk: function(t, a) {
        for (var e = [], o = 0, s = t.length; o < s; o += a) e.push(t.slice(o, o + a));
        return e;
    },
    getMoreData: function() {
        var t = this;
        if (this.data.page != this.data.total_page) if (this.data.page >= this.data.total_page) t.setData({
            loading: !0
        }); else {
            this.setData({
                page: this.data.page + 1
            });
            var a = e.getNetAddresss("plugin.store-cashier.frontend.store.store.get-store-list-to-page"), o = e.qqMapTransBMap(parseFloat(t.data.point.lng), parseFloat(t.data.point.lat));
            a += "&kwd=", a += "&lng=" + (o.lng ? o.lng : ""), a += "&lat=" + (o.lat ? o.lat : ""), 
            a += "&city_name=" + this.data.city, a += "&page=" + this.data.page, a += "&is_aggregation=1", 
            e._getNetWork({
                url: a,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var o = e.data;
                        t.setData({
                            loading: !1
                        }), o.current_page >= o.last_page && t.setData({
                            loading: !0
                        }), t.setData({
                            stores: t.data.stores.concat(o.data)
                        });
                    } else t.setData({
                        page: t.data.page - 1,
                        loading: !0,
                        isLoadMore: !1
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    tolocation: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation/o2oLocation"
        });
    },
    bannerClick: function(t) {
        var a = t.currentTarget.dataset.item;
        a && a.min_url ? this.goUrl(a.min_url) : wx.showToast({
            title: "请设置链接",
            icon: "none",
            duration: 2e3
        });
    },
    goUrl: function(t) {
        if (t) try {
            wx.navigateTo({
                url: t
            });
        } catch (a) {
            wx.showToast({
                title: "链接设置错误:" + t,
                icon: "none",
                duration: 2e3
            });
        }
    },
    tosearch: function() {
        this.data.city ? wx.navigateTo({
            url: "/packageC/o2o/o2oSearch/o2oSearch?city=" + this.data.city + "&point=" + JSON.stringify(this.data.point)
        }) : wx.showToast({
            icon: "none",
            title: "请先选择城市",
            duration: 1e3
        });
    },
    getStorePage: function() {
        var t = this, a = e.getNetAddresss("plugin.store-cashier.frontend.store.store.get-store-page"), o = e.qqMapTransBMap(parseFloat(t.data.point.lng), parseFloat(t.data.point.lat));
        o.lng || (o.lng = "", o.lat = ""), t.setData({
            page: 1
        }), e._getNetWork({
            url: a,
            data: {
                kwd: "",
                lng: o.lng,
                lat: o.lat,
                city_name: t.data.city,
                page: t.data.page
            },
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    e.data.store_list ? (t.getStores(e.data.store_list), console.log("gggggggggggggggg", e.data.store_list_style), 
                    t.setData({
                        openTemplate: e.data.store_list_style || 0
                    })) : t.setData({
                        stores: []
                    }), e.data.customer_development && t.setData({
                        customer: e.data.customer_development,
                        plugin_name: e.data.customer_development_name
                    }), t.setData({
                        category: e.data.category_list ? e.data.category_list : [],
                        hot_arrondi: e.data.hot_arrondi || {}
                    });
                    var o = t.chunk(t.data.category, 10);
                    t.setData({
                        category_10: o
                    }), t._indexData(e.data.get_default), t.getShopData(e.data.get_tab), t.gettitle();
                } else t.setData({
                    stores: [],
                    page: 1
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getShopData: function(a) {
        this.setData({
            shop: a
        });
        var e, o = t(this.data.shop);
        try {
            for (o.s(); !(e = o.n()).done; ) {
                var s = e.value;
                if (s.is_open) {
                    this.setData({
                        is_open: s.is_open
                    });
                    break;
                }
            }
        } catch (t) {
            o.e(t);
        } finally {
            o.f();
        }
        console.log(this.data.is_open, "is_open");
    },
    gotoGrouplist: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oGrouplist/o2oGrouplist"
        });
    },
    toDetail: function(t) {
        var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.storeid;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a + "/" + e + "&name=group"
        });
    },
    tocustomer: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    tokerSetMeal: function() {
        wx.navigateTo({
            url: "/packageH/toker/tokerIndex/tokerIndex?city=" + this.data.city + "&point=" + JSON.stringify(this.data.point)
        });
    }
});